<template>
	<view class="container">
		<rich-text :nodes="htmlNodes"></rich-text>
	</view>
</template>

<script>
	import { userAgreement } from '@/api/my.js'
	export default {
		data() {
			return {
				htmlNodes: '',
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				var that = this;
				userAgreement({
					type: 2
				}).then(res => {
					if (res.code == 0) {
						this.htmlNodes = res.data.content
						this.htmlNodes= that.imgDesc(this.htmlNodes);
					}
				})
			},
			imgDesc(html){
			  // return str.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin-top:10px"');
				html = html.replace(/style=""/gi,'');
				html = html.replace(/<p>/gi,"<p style='width:100%'>");
				// html = html.replace(/<\/p>/gi,'');
				let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
				    match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
				    match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
				    match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
				    return match;
				  });
				  newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
				    match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
				    return match;
				  });
				  // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
				  newContent = newContent.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin-top:0;margin-bottom:7px;"');
				  return newContent;
			}
		}
	}
	
</script>

<style scoped>
	.container {
		width: 750rpx;
		height: 100vh;
		background: #f3f8fc;
		padding: 30rpx;
		line-height: 54rpx;
		text-indent:2em;
	}

</style>